package LeetCode;

public class LC_058_LengthofLastWord {
    public static void main(String[] args) {

    }

    static class Solution {
        public int lengthOfLastWord(String s) {
            int len = s.length(),
                    i = len - 1,
                    count = 0;
            while (i >= 0 && s.charAt(i) == ' ')
                i--;
            for (; i >= 0; i--) {
                char ch = s.charAt(i);
                if (ch != ' ')
                    count++;
                else
                    break;
            }
            return count;
        }
    }

}
